package com.example.mymusicdisplay.view.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.mymusicdisplay.R;
import com.example.mymusicdisplay.databinding.TitleLayoutBinding;

import java.util.List;

/**
 * author: ts
 * created on: 2021/10/8 下午5:33
 * description:
 */
public class ViewPagerAdapter extends FragmentPagerAdapter {
    private static final String TAG = "ViewPagerAdapter";

    private List<Fragment> mFragmentList;
    private Context mContext;
    private TitleLayoutBinding mLayoutBinding;

    public ViewPagerAdapter(@NonNull FragmentManager fm, List<Fragment> fragments, Context context) {
        super(fm);
        mFragmentList = fragments;
        Log.d(TAG, "ViewPagerAdapter: ");
        mContext = context;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public View getCustomView(int position) {
        Log.d(TAG, "getCustomView: ");
        mLayoutBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext),
            R.layout.title_layout, null, false);
        switch (position) {
            case 0:
                mLayoutBinding.itemImage.setImageResource(R.drawable.item_search_background);
                mLayoutBinding.itemText.setText("发现");
                break;
            case 1:
                mLayoutBinding.itemImage.setImageResource(R.drawable.item_users_background);
                mLayoutBinding.itemText.setText("我的");
                break;
            default:
                break;
        }
        return mLayoutBinding.getRoot();
    }
}
